Source Code Viewer - Example 1 - ViewCountryAction

package name.matthewgreet.example1.action;

import javax.servlet.http.HttpSession;

import org.apache.struts2.convention.annotation.Action;
import org.apache.struts2.convention.annotation.InterceptorRef;
import org.apache.struts2.convention.annotation.Result;
import org.apache.struts2.convention.annotation.Results;

import com.opensymphony.xwork2.ActionSupport;

import name.matthewgreet.example1.common.AbstractActionSupport;
import name.matthewgreet.example1.common.SearchResults;
import name.matthewgreet.example1.form.CountryForm;
import name.matthewgreet.example1.vo.CountryVO;


/**
 * Displays country from in-memory table. 
 */
@InterceptorRef("ViewStack")
@Results({
	@Result(name=ViewCountryListAction.RESULT_RESTART, type="redirectAction", params = {"namespace", "/", "actionName", "FindCountryListInitial"}),
	@Result(name=ActionSupport.SUCCESS, location="/pages/Country.jsp")
})
public class ViewCountryAction extends AbstractActionSupport {
	private static final long serialVersionUID = -7979376337555804889L;
	
	private Integer index;
	private SearchResults<CountryVO> searchResults;
	private CountryForm form;
	
	
    @Action("/ViewCountry")
    @Override
    public String execute() throws Exception {
    	HttpSession session;
    	
    	session = getBrowserTabSession();
    	searchResults = ViewCountryListAction.retrieveSearchResults(session);
	    if (searchResults != null) {
	    	if (index != null) {
	    		searchResults.setSelectedIndex(index);
	    	}
	    	form = new CountryForm(searchResults.getSelected());
			return SUCCESS;
	    } else {
	    	return ViewCountryListAction.RESULT_RESTART;
	    }
    }

	public Integer getIndex() {
		return index;
	}
	public void setIndex(Integer index) {
		this.index = index;
	}

	public SearchResults<CountryVO> getSearchResults() {
		return searchResults;
	}

	public CountryForm getForm() {
		return form;
	}

}